import { defineStore } from 'pinia'
import { getUserInfo } from '@/api/userInfo'

export const useUserInfor = defineStore('userinfor', {
  state: () => ({
    imgUrl: '',
    name: '',
    sex: '',
    department: '',
    identity: '',
    account: null,
    email: ''
  }),
  actions: {
    async userInfo (id) {
      try {
        const res = await getUserInfo(id)
        this.imgUrl = 1
        this.name = 1
        this.sex = 1
        this.department = res.department
        this.identity = res.identity
      } catch (error) {
        console.error('Failed to fetch user info:', error)
      }
    }
  },
  persist: true
})
